home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / gui / pmdev.lha / PopupMenuDeveloper / Demos / BigMenu.c next >
Encoding:
C/C++ Source or Header  |  1997-06-23  |  2.9 KB  |  98 lines

  1. //
  2. // $VER: BigMenu.c 1.0 (12.6.97)
  3. //
  4. // Popup Menu library test program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. // This little hack is intended to test the submenus.
  11. //
  12. // WARNING! When the menu runs out of stack, it will end in a crash!
  13. // (It uses about <20 bytes per menu, so it will take a while.)
  14. //
  15.  
  16. #include <intuition/intuition.h>
  17.  
  18. #include <clib/intuition_protos.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/alib_protos.h>
  21.  
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25.  
  26. #include <libraries/pm.h>
  27. #include <proto/pm.h>
  28.  
  29. struct IntuitionBase    *IntuitionBase;
  30. struct GfxBase        *GfxBase;
  31. struct PopupMenuBase    *PopupMenuBase;
  32.  
  33. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  34.             // The font in this window's rastport will be used for the menu.
  35.  
  36. void main()
  37. {
  38.     BOOL r=TRUE;
  39.     struct IntuiMessage *im,imsg;
  40.     struct PopupMenu *p;
  41.  
  42.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  43.     if(PopupMenuBase) {
  44.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  45.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  46.  
  47.         p=PMMenu("Big Menu"),    // Create a big menu...
  48.             PMItem("Submenu"), PM_Sub, NULL, PM_ID, 20, End,
  49.             PMBar,    End,
  50.             PMItem("Quit"),    PM_UserData,    5,    End,
  51.             End;
  52.  
  53.         if(p) {
  54.  
  55.             PM_SetItemAttrs(PM_FindItem(p, 20), PM_Sub, p, TAG_DONE);    // Link the menu to itself...
  56.  
  57.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  58.                     WA_RMBTrap,    TRUE,
  59.                     WA_DragBar,    TRUE,
  60.                     WA_Width,    150,
  61.                     WA_Height,    100,
  62.                     WA_Left,    150,
  63.                     WA_Top,        0,
  64.                     WA_Title,    "BigMenu",
  65.                     WA_CloseGadget,    TRUE,
  66.                     TAG_DONE);
  67.             if(w) {
  68.                 while(r) {
  69.                     WaitPort(w->UserPort);                        // Wait for a message
  70.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  71.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  72.                         ReplyMsg((struct Message *)im);                // Reply the message
  73.  
  74.                         switch(imsg.Class) {
  75.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  76.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  77.                                 r=(BOOL)((ULONG)(PM_OpenPopupMenu(w,
  78.                                         PM_Menu,        p,
  79.                                         PM_Code,        imsg.Code,    // Must always be there!
  80.                                         TAG_DONE))-5);
  81.                             break;
  82.                         }
  83.                     }
  84.                 }
  85.                 CloseWindow(w);
  86.             } else printf("Window error!\n");
  87.  
  88. // Now it would be nice to free the menu, but the two lines below will cause
  89. // a crash, at least with the current release of popupmenu.library...
  90. //
  91. //            PM_SetItemAttrs(PM_FindItem(p, 20), PM_Sub, NULL, TAG_DONE);
  92. //            PM_FreePopupMenu(p);
  93.  
  94.         } else printf("Menu error!\n");
  95.         CloseLibrary((struct Library *)PopupMenuBase);
  96.     }
  97. }
  98.